var yajindan=({
	 loadList : function(){
			$$.showPreloader("加载中");
			$.ajax({
				url : "../contract/getContractListForAdmin.do",
				data : {
					userId: userId
				},
				type : "GET",
				dataType : 'json',
				cache : false,
				success : function(ret){
					$$.hidePreloader();
					var html = '';
					if(ret.rows && ret.rows.length>0){
						$(".houseAddr_").text(ret.rows[0].houseAddress);
						$("#contractId").val(ret.rows[0].contractId);
						$.each(ret.rows,function(i,n){
							html += "<option data-value='"+n.contractId+"' value='"+n.houseAddress+"'>"+n.houseAddress+"</option>";
						});
					}
					$("#houseAddr").html(html);
					 yajindan.queryDepotSliById();
				},
				error: function(){
					$$.hidePreloader();
					$$.toast("加载出错");
				}
			});
		},
		insertDepositSlip : function (){
			var userName=$("#userName").val();
			if(userName ==""){
				$$.alert("用户名不能为空");
				return false;
			}
			var payDate =$("#payDate").val();
			if(payDate ==""){
				$$.alert("支付日期不能为空");
				return false;
			}
			var money= $("#money").val();
			if(money ==""){
				$$.alert("支付金额不能为空");
				return false;
			}
			var houseAddr=$("#houseAddr").val();
			if(houseAddr == ""){
				$$.alert("合同不能为空");
				return false;
			}
			var bankName=$("#bankName").val();
			if(bankName == ""){
				$$.alert("银行名称不能为空");
				return false;
			}
			var payAccount=$("#payAccount").val();
			if(payAccount == ""){
				$$.alert("支付账号不能为空");
				return false;
			}
			$$.showPreloader("加载中");
			$.ajax({
				url : "../depositslip/insertDepositSlip.do",
				data : {
					userName : userName,
					payDate : payDate,
					money : money,
					houseAddr : houseAddr,
					userId : userId,
					contractId : $("#contractId").val(),
					bankName : bankName,
					payAccount : payAccount
				},
				type : "post",
				dataType : 'json',
				cache : false,
				success : function(ret){
					$$.hidePreloader();
					if(ret.success){
						$$.alert("创建押金单成功");
						window.location.href="./gasList.html?userId="+userId;
					}
					
				},
				error: function(){
					$$.hidePreloader();
					$$.toast("加载出错");
				}
			});
		},
		queryDepotSliById : function (){
			$$.showPreloader("加载中");
			$.ajax({
				url : "../depositslip/queryDepotSliById.do",
				data : {
					slipId : slipId
				},
				type : "post",
				dataType : 'json',
				cache : false,
				success : function(ret){
					$$.hidePreloader();
					if(ret.success && ret.list!=null){
						$("#userName").val(ret.list.userName);
						$("#payDate").val(common.timestampToTime(ret.list.payDate));
						$("#money").val(ret.list.money);
						$(".houseAddr_").text(ret.list.houseAddr);
						$(".userName_").text(ret.list.userName);
						$(".payDate_").text(common.timestampToTime(ret.list.payDate));
						$(".money_").text(ret.list.money);
						$(".bankName_").text(ret.list.bankName);
						$(".payAccount_").text(ret.list.payAccount);
						$("#bankName").val(ret.list.bankName);
						$("#payAccount").val(ret.list.payAccount);
						$("#houseAddr option[value='"+ret.list.houseAddr+"']").attr("selected","selected"); 
					}
					
				},
				error: function(){
					$$.hidePreloader();
					$$.toast("加载出错");
				}
			});
		},
		updateDepositSlip : function (){
			var userName=$("#userName").val();
			if(userName ==""){
				$$.alert("用户名不能为空");
				return false;
			}
			var payDate =$("#payDate").val();
			if(payDate ==""){
				$$.alert("支付日期不能为空");
				return false;
			}
			var money= $("#money").val();
			if(money ==""){
				$$.alert("支付金额不能为空");
				return false;
			}
			var houseAddr=$("#houseAddr").val();
			if(houseAddr == ""){
				$$.alert("合同不能为空");
				return false;
			}
			var bankName=$("#bankName").val();
			if(bankName == ""){
				$$.alert("银行名称不能为空");
				return false;
			}
			var payAccount=$("#payAccount").val();
			if(payAccount == ""){
				$$.alert("支付账号不能为空");
				return false;
			}
			$$.showPreloader("加载中");
			$.ajax({
				url : "../depositslip/updateDepositSlip.do",
				data : {
					userName : userName,
					payDate : payDate,
					money : money,
					houseAddr : houseAddr,
					userId : userId,
					contractId : $("#contractId").val(),
					slipId : slipId,
					bankName : bankName,
					payAccount : payAccount
				},
				type : "post",
				dataType : 'json',
				cache : false,
				success : function(ret){
					$$.hidePreloader();
					if(ret.success){
						$$.alert("更新押金单成功");
						window.location.href="./gasList.html?userId="+userId;
					}
				},
				error: function(){
					$$.hidePreloader();
					$$.toast("加载出错");
				}
			});
		},
		delDepotSliById : function (){
			  $$.confirm('真的要删除押金单吗?', function () {
				  $$.showPreloader("加载中");
					$.ajax({
						url : "../depositslip/delDepotSliById.do",
						data : {
							slipId : slipId
						},
						type : "post",
						dataType : 'json',
						cache : false,
						success : function(ret){
							$$.hidePreloader();
							if(ret.success ){
								$$.alert("删除押金单成功");
								window.location.href="./gasList.html?userId="+userId;
							}
						},
						error: function(){
							$$.hidePreloader();
							$$.toast("加载出错");
						}
					});
		      });
			
		}
})